//---------------------------------------------------------------------------
#ifndef CRibH
#define CRibH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "CEdit.h"
#include "CtrlStd.h"
//---------------------------------------------------------------------------
#define LONGUEUR_DESIGNATION_RIB 25
#define LONGUEUR_BANQUE_RIB       5
#define LONGUEUR_GUICHET_RIB      5
#define LONGUEUR_COMPTE_RIB      11
#define LONGUEUR_CLE_RIB          2

#define FORMER_RIB(Designation,Banque,Guichet,Compte,cle) (Designation + "#" + Banque + "#" + Guichet + "#" + Compte + "#" + cle)
#define RIB_VIDE "####"
//---------------------------------------------------------------------------
class PACKAGE_CTRLSTD CRib : public TCustomPanel
{
private:
  CEdit *m_pEDesignation;
  CEdit *m_pEBanque;
  CEdit *m_pEGuichet;
  CEdit *m_pENumCpt;
  CEdit *m_pERIB;
  
  TLabel *m_pLDesignation;
  TLabel *m_pLBanque;
  TLabel *m_pLGuichet;
  TLabel *m_pLNumCpt;
  TLabel *m_pLRIB;

  int    m_nLeft;
  int    m_nTop;
  bool   m_bReadOnly;
  bool   m_bEnabled;
  bool   m_MessageErreur;
  bool   m_bDeuxLignes;

  void __fastcall InitComposantInterne( CEdit **pIntEdit, TLabel **pIntLabel, int nMaxChar, const AnsiString &strLabel, CEdit::FiltresEdit eFiltre);
  void __fastcall ReplaceComposantInterne( CEdit *pIntEdit, TLabel *pIntLabel);

  AnsiString __fastcall GetDesignation( void) const { return m_pEDesignation->Text; };
  AnsiString __fastcall GetBanque     ( void) const { return      m_pEBanque->Text; };
  AnsiString __fastcall GetGuichet    ( void) const { return     m_pEGuichet->Text; };
  AnsiString __fastcall GetCompte     ( void) const { return      m_pENumCpt->Text; };
  AnsiString __fastcall GetRib        ( void) const { return         m_pERIB->Text; };

  void __fastcall SetDesignation  ( const AnsiString &strValue) { m_pEDesignation->Text = strValue; };
  void __fastcall SetBanque       ( const AnsiString &strValue) {      m_pEBanque->Text = strValue; };
  void __fastcall SetGuichet      ( const AnsiString &strValue) {     m_pEGuichet->Text = strValue; };
  void __fastcall SetCompte       ( const AnsiString &strValue) {      m_pENumCpt->Text = strValue; };
  void __fastcall SetRib          ( const AnsiString &strValue) {         m_pERIB->Text = strValue; };

  AnsiString __fastcall GetDomiciliation( void) const;
  void       __fastcall SetDomiciliation( const AnsiString &strValue);

  AnsiString __fastcall ConvAlpha2Numeric( const AnsiString &strValue) const;
  int        __fastcall CalculRIB( void) const;

  void       __fastcall SetReadOnly     ( bool bValue);
  void       __fastcall SetEnabled      ( bool bValue);
  void       __fastcall SetDeuxLignes   ( bool bValue);
  bool       __fastcall GetIsValide     ( void) const;
  bool       __fastcall GetIsEmpty      ( void) const;

protected:
  DYNAMIC void __fastcall DoExit( void);

  #define COMPLETER(chaine,taille) if (!chaine.IsEmpty() && (chaine.Length() < taille)) \
                                     chaine = AnsiString::StringOfChar('0',taille - chaine.Length()) + chaine; \
                                   return chaine

public:
  __fastcall CRib(TComponent* Owner);
  virtual void __fastcall SetFocus(void);

  __property AnsiString Designation   = { read=GetDesignation  , write=SetDesignation   };
  __property AnsiString Banque        = { read=GetBanque       , write=SetBanque        };
  __property AnsiString Guichet       = { read=GetGuichet      , write=SetGuichet       };
  __property AnsiString Compte        = { read=GetCompte       , write=SetCompte        };
  __property AnsiString Rib           = { read=GetRib          , write=SetRib           };
  __property AnsiString Domiciliation = { read=GetDomiciliation, write=SetDomiciliation };

  __property bool IsValide = { read=GetIsValide };
  __property bool IsEmpty = { read=GetIsEmpty };
  __property bool AfficherMessageErreurEnAutomatique = { read=m_MessageErreur, write=m_MessageErreur, default=1};

  static AnsiString & __fastcall CompleterBanque(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_BANQUE_RIB);}
  static AnsiString & __fastcall CompleterGuichet(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_GUICHET_RIB);}
  static AnsiString & __fastcall CompleterCle(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_CLE_RIB);}
  static AnsiString & __fastcall CompleterNumCompte(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_COMPTE_RIB);}

__published:
  __property Font;
  __property Height = { stored=false };
  __property Width  = { stored=false };
  __property ParentFont;
  __property bool ReadOnly      = { read=m_bReadOnly    , write=SetReadOnly     , default=0 };
  __property bool Enabled       = { read=m_bEnabled     , write=SetEnabled      , default=1 };
  __property bool DeuxLignes    = { read=m_bDeuxLignes  , write=SetDeuxLignes   , default=0 };
  __property Visible;
};
//---------------------------------------------------------------------------
// Déclaration des fonctions pouvant être appelées de l'extérieur
extern PACKAGE_CTRLSTD AnsiString  __fastcall CalculerIBAN(const AnsiString &pBanque, const AnsiString &pGuichet, const AnsiString &pCompte, const AnsiString &pCle);
#endif